<?php 
  require_once("includes/config.php"); 
  
  $body_class = "login-page";
  if ($_SERVER["REQUEST_METHOD"] == "POST") 
  {
    $name = $_POST["name"];
    $pass = sha1($_POST['user_password']);
    $result= query("SELECT * FROM apartments_owner WHERE password = ? and username = ? or email =?  ",$pass,$name,$name);
     
    if(empty($result))
    {
      $_SESSION["error_message"] = "البيانات التى قمت بإدخالها غير صحيحة";
       redirect("login.php");
    }
        
    else
    {
      $row = $result[0];
      $_SESSION["login_user"] = $row["first_name"]. " ".$row["last_name"] ; 
      $_SESSION["user_id"] = $row["id"] ; 
      $_SESSION["organization"] = $row["orgnanization_name"] ; 
      $_SESSION["phone"] = $row["phone"] ; 
      $_SESSION["place"] = $row["place"] ; 
      $_SESSION["success"]= "Welcome " .$_SESSION["login_user"] ;
      redirect("index.php");
    }
    
  
  }
  else
  {
    if(isset($_SESSION["user_id"]))
      redirect("index.php");
    else
      render("login.php", array("title"=>"تسجيل الدخول","body_class"=>$body_class));
  }

?>